package com.zpself.module.算法练习.二叉树;

/**
 * @author By ZengPeng
 * @Description
 * @date in  2021/1/20 19:13
 * @Modified By
 */
public class 力扣_226_翻转二叉树 {
    public static void main(String[] args) {
        TreeNode root = TreeNode.initRoot();
        TreeNode treeNode = invertTree(root);
        System.out.println(treeNode);
    }

    public static TreeNode invertTree(TreeNode root){
        if (root == null) return null;
        // 保存右子树
        TreeNode rightTree = root.right;
        // 交换左右子树的位置
        root.right = invertTree(root.left);
        root.left = invertTree(rightTree);
        return root;
    }
}
